<?php

class sfGuardUserGroupForm extends BaseFormDoctrine
{

	public function setup()
	{
		$this->setWidgets(array(
			'group_id' => new WidgetFormHiddenInfo(array('model' => 'sfGuardGroup', 'column' => 'name','label' => 'Grupo')),
			'user_id' => new WidgetFormAutocomplete(array('model' => 'sfGuardUser', 'label' => 'Usuario', 'action' => 'usuario/buscar'))
		));

		$this->setValidators(array(
			'user_id' => new sfValidatorDoctrineChoice(array('model' => 'sfGuardUser', 'required' => true)),
			'group_id' => new sfValidatorDoctrineChoice(array('model' => 'sfGuardGroup', 'required' => true))
		));

		$validator = new ValidatorCombinedKey(array('model' => $this->getModelName()));
		$validator->setMessage('invalid', 'El usuario ya pertenece al grupo');
		$this->validatorSchema->setPostValidator($validator);

		$this->widgetSchema->setNameFormat('sf_guard_user_group[%s]');

		$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

		$this->setupInheritance();

		parent::setup();
	}

	public function getModelName()
	{
		return 'sfGuardUserGroup';
	}

}
